;(function ($) {

    let page = parseInt(GetQueryString("page")) || 1;
    let limit = parseInt(GetQueryString("limit")) || 6;
    let speciesId = GetQueryString("speciesId") || '052e89a3f93c493782967523e2f7d830';
    console.log(page, limit, speciesId);


/*    //分类
    $.ajax({
        url: "/api/agt_agritech/page",
        data: {

        },
        dataType: "json",
        async: false,
        success: function (result) {

        }
    });*/


    //农技
    $.ajax({
        url: "/api/agt_agritech/query",
        data: {
            page: page,
            limit: limit
            // ,speciesId: speciesId
        },
        dataType: "json",
        async: true,
        success: function (result) {
            let div = $(".detail_informationContentM").find(".detail_informationContentMleft");
            $.each(result.data, function (idx, obj) {
                let agtHtml = `<li class="col-md-4">
                        <a href="/agritech/${obj.id}">
                          <img class="img-responsive" src="${obj.agritechCover}" alt=""/>
                          <h3>${obj.agritechTitle}</h3>
                          <p>${obj.agritechAbstract}</p>
                        </a>
                      </li>`;
                div.append(agtHtml);
            });


            let num = (result.count + limit - 1) / limit;

            //分页
            $("#Pagination").pagination(num, {
                link_to: "javascript:;",
                current_page: page - 1,
                callback: function (idx, cont) {
                    location.href = `/agritech?page=${idx + 1}&limit=${limit}`;
                }
            });
        }
    });

    function GetQueryString(variable) {
        // var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        // var r = window.location.search.substr(1).match(reg);
        // if (r != null) return unescape(r[2]);return null;
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }

    function getContextPath() {
        let pathName = document.location.pathname;
        let index = pathName.substr(1).indexOf("/");
        let result = pathName.substr(0, index + 1);
        console.log(pathName,index,result);
        return result;
    }

    function getId() {
        let pathName = document.location.pathname;
        let index = pathName.substr(1).lastIndexOf("/");
        let id = pathName.substr(index + 2);
        console.log(pathName,index,id);
        return id;
    }
})(window.jQuery);